package it.mp.multitask.preference;

import it.mp.multitask.R;
import it.mp.multitask.utility.PatternEntry;
import android.content.Context;
import android.preference.Preference;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;

public class ImagePreference extends Preference {

	private ImageView iv;

	public ImagePreference(Context context, AttributeSet attrs) {
		super(context, attrs);
	}
	@Override
	protected View onCreateView(ViewGroup parent) {
		LinearLayout layout = new LinearLayout(getContext());
		LinearLayout.LayoutParams params1 = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.FILL_PARENT);
		layout.setOrientation(LinearLayout.HORIZONTAL);

		iv = new ImageView(getContext());
		iv.setBackgroundResource(PatternEntry.decodePattern(getPreferenceManager().getSharedPreferences().getString(
				getContext().getResources().getString(R.string.pref_background_theme), PatternEntry.primoValore()), 
				Integer.parseInt(getPreferenceManager().getSharedPreferences().getString(getContext().getResources().getString(R.string.theme_main_new), "0"))));
		iv.setLayoutParams(params1);
		iv.setMinimumHeight(54);
		layout.addView(iv);
		layout.setId(android.R.id.widget_frame);

		return layout;
	}

	public void cambiaSfondo(int resourceId) {
		iv.setBackgroundResource(resourceId);
	}

}
